//
//  CenterViewController.m
//  JobFreely
//
//  Created by Dale on 2017/5/23.
//  Copyright © 2017年 Dale. All rights reserved.
//

#import "CenterViewController.h"
#import "JFSettingViewController.h"
#import "JFScrumMainViewController.h"
#import "JFFriendMainViewController.h"
#import "JFFeedBackViewController.h"
#import "MMDrawerBarButtonItem.h"
#import "BaseNavigationViewController.h"
@interface CenterViewController ()

@end

@implementation CenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    [self loadViewControllers];
}


- (void)loadViewControllers {
    JFScrumMainViewController *scrumVC  = [[JFScrumMainViewController alloc] initWithNibName:@"JFScrumMainViewController" bundle:nil];
    BaseNavigationViewController *srumNav = [[BaseNavigationViewController alloc] initWithRootViewController:scrumVC];
    [self addChildViewController:srumNav];
    
    JFFriendMainViewController *friendVC  = [[JFFriendMainViewController alloc] initWithNibName:@"JFFriendMainViewController" bundle:nil];
    BaseNavigationViewController *friendNav = [[BaseNavigationViewController alloc] initWithRootViewController:friendVC];
    [self addChildViewController:friendNav];
    
    JFSettingViewController *settingVC  = [[JFSettingViewController alloc] initWithNibName:@"JFSettingViewController" bundle:nil];
    BaseNavigationViewController *settingNav = [[BaseNavigationViewController alloc] initWithRootViewController:settingVC];
    [self addChildViewController:settingNav];
    
    
    JFFeedBackViewController *feedbackVC  = [[JFFeedBackViewController alloc] initWithNibName:@"JFFeedBackViewController" bundle:nil];
    BaseNavigationViewController *feedbackNav = [[BaseNavigationViewController alloc] initWithRootViewController:feedbackVC];
    [self addChildViewController:feedbackNav];


    [self.view addSubview:srumNav.view];
    [srumNav.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    self.curIndex = EMainMenuScrum;
}

//  切换各个标签内容
- (void)replaceControllerToIndex:(NSInteger)index {
    if (self.curIndex == index || index < 0) {
        return;
    }
    UIViewController *currentVC = self.childViewControllers[self.curIndex];
    UIViewController *targetVC = self.childViewControllers[index];
    [self transitionFromViewController:currentVC toViewController:targetVC duration:0.0 options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionShowHideTransitionViews animations:nil completion:^(BOOL finished) {
        if (finished) {
            [targetVC didMoveToParentViewController:self];
            [self.view addSubview:targetVC.view];
            [targetVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(self.view);
            }];

            [currentVC willMoveToParentViewController:nil];
//            [currentVC removeFromParentViewController];
            [currentVC.view removeFromSuperview];
            self.curIndex = index;
        }
    }];
}

@end
